package org.chatboleh.bean;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

import org.chatboleh.exception.EDMException;

public class Payee extends DataObject {

	private String name;
	private String address;
	private String email;
	private String phone;
	private Timestamp cdate;

	public Payee(long i) {
		super(i);
	}

	public Payee() {
	}

	@Override
	protected String fieldnames() {
		return "name,address,email,phone,cdate";
	}

	@Override
	public void prepareUpdate() throws EDMException {
		try {
			ps.setString(1, this.name);
			ps.setString(2, this.address);
			ps.setString(3, this.email);
			ps.setString(4, this.phone);
			ps.setTimestamp(5, this.cdate);
		} catch (SQLException e) {
			throw new EDMException(e);
		}

	}

	@Override
	protected String tablename() {
		return "payee";
	}


	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	@Override
	protected void loadResultSetIntoObject(ResultSet resultset) {
		try {
			this.name = resultset.getString("name");
			this.address = resultset.getString("address");
			this.email = resultset.getString("email");
			this.phone = resultset.getString("phone");
			this.cdate = resultset.getTimestamp("cdate");
		} catch (SQLException e) {
			logger.error(e);
		}

	}

	@Override
	public List<Payee> getList(String criteria) throws EDMException {
		List<Payee> list = new ArrayList<Payee>();

		try {
			openConnection();
			prepareStatement(selectlistquery(criteria));
			executeQuery();
			while (resultset.next()) {
				Payee payee = new Payee();
				payee.id = resultset.getLong("id");
				payee.loadResultSetIntoObject(resultset);
				list.add(payee);
			}
		} catch (SQLException e) {
			throw new EDMException(e);
		} finally {
			closeStatement();
		}
		return list;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public Timestamp getCdate() {
		return cdate;
	}

	public void setCdate(Timestamp cdate) {
		this.cdate = cdate;
	}

}
